package com.reflect;

import java.lang.reflect.Field;

/**
 * FiledTest--bdqnPractice
 *
 * @author: Jovi
 * @createTime: 2017-08-02 11:30
 **/
public class FiledTest {

    public static void main(String[] args) {

        Class cls = People.class;

        try {
            People p = (People)cls.newInstance();
            Field f1 = cls.getDeclaredField("name");
            f1.setAccessible(true);
            f1.set(p,"name1");
            System.out.println(p.getName());
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }
}
